package org.example.zxk.bk.controller;

import org.example.common.config.CommonResult;
import org.example.zxk.bk.model.dto.AddUserDTO;
import org.example.zxk.bk.model.dto.QueryUserDTO;
import org.example.zxk.bk.service.BkuserZckService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;

@RestController
@RequestMapping("/user")
public class UserZxkBkController {

    @Resource
    private BkuserZckService bkuserZckService;
    private static final SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    @PostMapping("/register")
    public CommonResult create(@RequestBody AddUserDTO dto) {
        try {
            bkuserZckService.create(dto);
        } catch (Exception e) {
            return CommonResult.failed(e.getMessage());
        }
        return CommonResult.success("创建成功");
    }

    @PostMapping("/login")
    public CommonResult login(@RequestBody QueryUserDTO dto) {
        try {
            return bkuserZckService.login(dto);
        } catch (Exception e) {
            return CommonResult.failed(e.getMessage());
        }
    }

    @PostMapping("/query/list")
    public CommonResult queryList(@RequestBody QueryUserDTO dto) {
        try {
            return bkuserZckService.queryList(dto);
        } catch (Exception e) {
            e.printStackTrace();
            return CommonResult.failed("查询失败");
        }
    }
}
